package com.jianganming.clone;

import java.io.Serializable;

/**
 * 浅克隆
 */
public class Clazz implements Cloneable {
    private String className;
    private Student student;

    @Override
    protected Clazz clone() throws CloneNotSupportedException {
        return (Clazz)super.clone();
    }

    public Clazz(String className, Student student) {
        this.className = className;
        this.student = student;
    }

    public String getClassName() {
        return className;
    }

    public Student getStudent() {
        return student;
    }
}


class Student implements Serializable {
    private int age;
    private String anme;

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getAnme() {
        return anme;
    }

    public void setAnme(String anme) {
        this.anme = anme;
    }

    @Override
    public String toString() {
        return "Student{" +
                "age=" + age +
                ", anme='" + anme + '\'' +
                '}';
    }
}

class CitationTest1{
    public static void main(String[] args)throws Exception {
        Student student1 = new Student();
        student1.setAge(12);
        student1.setAnme("张三");
        System.out.println(student1);
        Clazz clazz = new Clazz("高一01",student1);
        Clazz clone = clazz.clone();
        Student student = clone.getStudent();
        student.setAnme("李四");
        System.out.println(student);
        System.out.println(student1);//这里被修改了，按理说不应该被修改，不是克隆对象
    }
}
